package br.com.marcelo.reservasis.client.componentes;

import br.com.aroeirasoftware.gwtcomponents.client.components.ASComboBox;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASCommandBar;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASMenuBar;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASMessagePanel;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASPage;
import br.com.aroeirasoftware.gwtcomponents.client.i18n.ASGWTComponentsI18N;
import br.com.marcelo.reservasis.client.i18n.ReservaSISI18N;
import br.com.marcelo.reservasis.client.pagina.apartamento.ApartamentoPesquisarPagina;
import br.com.marcelo.reservasis.client.pagina.hospede.HospedePesquisarPagina;
import br.com.marcelo.reservasis.client.pagina.reserva.ReservaEstadiaPesquisarPagina;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.MenuBar;

/**
 *
 * @author Marcelo
 */
public class ReservaSISBarraMenu extends ASMenuBar {

    private Image iHelp;
    private Image iAbout;
    private Image iClose;
    private ClickHandler clickHandler;
    private ASCommandBar barraImagens;
    private Integer index = 0;
    private static final String STYLE_NAME_COMANDO = "as-comando";

    public ReservaSISBarraMenu() {
        initComponents();
    }

    private void initComponents() {
        clickHandler = new ClickHandler() {

            public void onClick(ClickEvent event) {
                Object source = event.getSource();

                if (source == iHelp) {
                    ASMessagePanel.getInstance().exibirMensagem("Ajuda ReservaSIS",
                            ASMessagePanel.ASMessageSeverity.INFORMACAO,
                            ASMessagePanel.ASMessageOption.OK);
                }

                if (source == iAbout) {
                    ASMessagePanel.getInstance().exibirMensagem("Sobre ReservaSIS",
                            ASMessagePanel.ASMessageSeverity.INFORMACAO,
                            ASMessagePanel.ASMessageOption.OK);
                }

                if (source == iClose) {
                    ReservaSISApplication.getInstance().logout();
                }
            }
        };


        iHelp = ASGWTComponentsI18N.images.questionButton().createImage();
        iHelp.addClickHandler(clickHandler);
        iHelp.addStyleName(STYLE_NAME_COMANDO);

        iAbout = ASGWTComponentsI18N.images.informationButton().createImage();
        iAbout.addClickHandler(clickHandler);
        iAbout.addStyleName(STYLE_NAME_COMANDO);

        iClose = ASGWTComponentsI18N.images.doorOpenOut().createImage();
        iClose.addClickHandler(clickHandler);
        iClose.addStyleName(STYLE_NAME_COMANDO);

        barraImagens = new ASCommandBar();
        barraImagens.addStyleName("barramenu");


        barraImagens.add(iHelp);
        barraImagens.add(iAbout);
        barraImagens.add(iClose);

        MenuBar mb = new MenuBar();
        mb.addItem("Apartamento", new Command() {

            public void execute() {
                new ApartamentoPesquisarPagina().abrir();
            }
        });
        mb.addItem(ReservaSISI18N.messages.reservaEstadia(), new Command() {

            public void execute() {
                new ReservaEstadiaPesquisarPagina(null, ReservaSISApplication.getInstance(), ReservaSISI18N.messages.tituloReservaEstadiaPesquisarPagina(),
                        ReservaSISI18N.messages.subtituloReservaEstadiaPesquisaPagina()).abrir();
            }
        });
        mb.addItem(ReservaSISI18N.messages.hospede(), new Command() {

            public void execute() {
                new HospedePesquisarPagina().abrir();
            }
        });
        setMenu(mb);
        setImagens(barraImagens);

    }
}
